<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>课程列表</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <style>
        .course-card {
            margin-bottom: 20px;
            height: 100%; /* Ensure cards in a row have same height */
            display: flex;
            flex-direction: column;
        }
        .course-card img {
            height: 200px;
            object-fit: cover; /* Crop image to fit */
        }
        .course-card .card-body {
            flex-grow: 1; /* Make card body expand */
            display: flex;
            flex-direction: column;
        }
        .course-card .card-text {
            flex-grow: 1; /* Make text area expand */
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-line-clamp: 3; /* Limit to 3 lines */
            -webkit-box-orient: vertical;
        }
        .course-card .card-footer {
            margin-top: auto; /* Push footer to bottom */
            background-color: transparent;
            border-top: none;
        }
    </style>
</head>
<body>

<nav class="navbar navbar-expand-lg navbar-light bg-light">
    <div class="container-fluid">
        <a class="navbar-brand" href="#">在线学习平台</a>
    </div>
</nav>

<div class="container mt-4">
    <h1>所有课程</h1>
    <hr>

    <div th:if="${successMessage}" class="alert alert-success" role="alert" th:text="${successMessage}"></div>
    <div th:if="${errorMessage}" class="alert alert-danger" role="alert" th:text="${errorMessage}"></div>

    <div th:if="${#lists.isEmpty(courses)}" class="alert alert-info" role="alert">
        目前还没有可用的课程。
    </div>

    <div class="row" th:if="${not #lists.isEmpty(courses)}">
        <div class="col-md-4" th:each="course : ${courses}">
            <div class="card course-card">
                <img th:src="${course.couPic != null ? course.couPic : '/images/default_course_cover.png'}"
                     class="card-img-top"
                     alt="课程封面"
                     onerror="this.onerror=null; this.src='/images/default_course_cover.png';"> <div class="card-body">
                <h5 class="card-title" th:text="${course.couName}">课程标题</h5>
                <p class="card-text" th:text="${course.couIntroduction}">课程简介...</p>
            </div>
                <div class="card-footer text-center">
                    <a th:href="@{/course/detail/{id}(id=${course.id})}" class="btn btn-primary">查看详情</a>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>